import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Spider-Man
 * Date: 2025-03-26
 * Time: 22:23
 */
public class MinimumSubarray {
    public static int minSubArrayLen(int target, int[] nums) {
        Arrays.sort(nums);
        int left = 0, right = 0, sum = 0, len = 0, count = 0;
        while(left < nums.length && right < nums.length) {
            if (nums[left] > target) {
                return 1;
            }
            if(count == 1) {
                count = 0;
                sum -= (nums[left - 1] + nums[right]);
            }
            sum += nums[right];
            if(sum >= target) {
                len = right - left + 1;
                if(len == 2) {
                    return len;
                }
                left++;
                count = 1;
            } else {
                right++;
            }
        }
        return len;
    }

    public static void main(String[] args) {
        int target = 213;
        int[] nums = {12,28,83,4,25,26,25,2,25,25,25,12};
        minSubArrayLen(target,nums);
    }
}
